home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / vbxwzrd / bmpfilm.c@ < prev    next >
Encoding:
Text File  |  1995-03-19  |  8.0 KB  |  225 lines

  1. //---------------------------------------------------------------------------
  2. // BmpFilm.c
  3. //---------------------------------------------------------------------------
  4. // Contains control procedure for BmpFilm control
  5. //---------------------------------------------------------------------------
  6.  
  7. #include <windows.h>
  8. #include "vbapi.h"
  9. #include "BmpFilm.h"
  10.  
  11. //---------------------------------------------------------------------------
  12. // Local Prototypes
  13. //---------------------------------------------------------------------------
  14. BOOL _export FAR PASCAL AboutDlgProc(HWND hDlg, USHORT msg, USHORT wp, LONG lp);
  15.  
  16. //---------------------------------------------------------------------------
  17. // Global Variables
  18. //---------------------------------------------------------------------------
  19. HANDLE hmodDLL;     
  20.  
  21. //---------------------------------------------------------------------------
  22. // BmpFilm Control Procedure
  23. //---------------------------------------------------------------------------
  24. LONG FAR PASCAL _export BmpFilmCtlProc
  25. (
  26.     HCTL   hctl,
  27.     HWND   hwnd,
  28.     USHORT msg,
  29.     USHORT wp,
  30.     LONG   lp
  31. )
  32. {   
  33.     LPBmpFilm BmpFilm;
  34.     BmpFilm = LpBmpFilmDEREF(hctl);
  35.     switch (msg)
  36.         {   
  37.         case WM_NCCREATE:       
  38.             BmpFilm->Col = 0;
  39.             BmpFilm->Row = 0;
  40.             VBSetControlProperty(hctl, IPROP_BmpFilm_Interval, 200);
  41.               VBSetControlProperty(hctl, IPROP_BmpFilm_Cols, 3);
  42.               VBSetControlProperty(hctl, IPROP_BmpFilm_Rows, 6);
  43.             break;
  44.         case WM_TIMER:
  45.             if (BmpFilm->Row==BmpFilm->Rows-1)
  46.               {
  47.               BmpFilm->Row = 0;
  48.               BmpFilm->Col++;
  49.               }
  50.             else BmpFilm->Row++;
  51.             if (BmpFilm->Col==BmpFilm->Cols)
  52.               {
  53.               BmpFilm->Row = 0;
  54.               BmpFilm->Col = 0;
  55.               }
  56.             InvalidateRect(hwnd, NULL, FALSE);
  57.             break;       
  58.         case WM_PAINT:
  59.             {
  60.             PAINTSTRUCT ps;
  61.             HDC  MemDC; 
  62.             HBRUSH hBrush;
  63.               HBRUSH hBrushOld;            
  64.               RECT   rect;
  65.               PIC    Pic;
  66.               HPIC   hPic;
  67.               BITMAP Bmp;
  68.               if (VBGetMode()==MODE_RUN) VBFireEvent(hctl, IEVENT_BmpFilm_Paint, NULL);
  69.             BeginPaint(hwnd, &ps);   
  70.             VBGetControlProperty(hctl, IPROP_BmpFilm_Picture, &hPic);
  71.             if (hPic!=0)
  72.               {
  73.               VBGetPic(hPic, &Pic);
  74.               hBrush = (HBRUSH)GetBrushOrg(ps.hdc);
  75.                 if (hBrush) hBrushOld = SelectObject(ps.hdc, hBrush);
  76.                 GetClientRect(hwnd, &rect);
  77.                 GetObject(Pic.picData.bmp.hbitmap, sizeof(BITMAP), (LPSTR)&Bmp);
  78.                 MemDC = CreateCompatibleDC(ps.hdc);
  79.                 SelectObject(MemDC, Pic.picData.bmp.hbitmap);                        
  80.                 BitBlt(ps.hdc,0,0,Bmp.bmWidth / BmpFilm->Rows,Bmp.bmHeight / BmpFilm->Cols,MemDC
  81.                   ,BmpFilm->Row*(Bmp.bmWidth / BmpFilm->Rows),BmpFilm->Col*(Bmp.bmHeight / BmpFilm->Cols),SRCCOPY);
  82.                 SelectObject(ps.hdc, hBrushOld);                        
  83.                 DeleteDC(MemDC);                               
  84.                 }
  85.             EndPaint(hwnd, &ps);
  86.             }
  87.             break;
  88.          case VBM_SETPROPERTY:
  89.             {
  90.             switch (wp)
  91.                 {
  92.                 case IPROP_BmpFilm_Picture:
  93.                     InvalidateRect(hwnd, NULL, TRUE);
  94.                     break;                           
  95.                 case IPROP_BmpFilm_Interval:
  96.                     if (VBGetMode()==MODE_RUN) 
  97.                       {          
  98.                       VBGetControlProperty(hctl, IPROP_BmpFilm_Interval, &BmpFilm->Interval);
  99.                       SetTimer(hwnd, 100, BmpFilm->Interval, NULL); 
  100.                       }
  101.                     break;                   
  102.                 case IPROP_BmpFilm_Cols:
  103.                     VBGetControlProperty(hctl, IPROP_BmpFilm_Cols, &BmpFilm->Cols);
  104.                     InvalidateRect(hwnd, NULL, TRUE);
  105.                     break;
  106.                 case IPROP_BmpFilm_Rows:                                               
  107.                     VBGetControlProperty(hctl, IPROP_BmpFilm_Rows, &BmpFilm->Rows);
  108.                     InvalidateRect(hwnd, NULL, TRUE);
  109.                     break;
  110.                 }
  111.             }
  112.             break;
  113.         case WM_USER:
  114.             VBDialogBoxParam(hmodDLL, "ABOUT", (FARPROC)AboutDlgProc, 0L);
  115.             break;
  116.         case VBM_INITPROPPOPUP:
  117.             if (wp==3)
  118.                 {
  119.                   PostMessage(hwnd,WM_USER,0,0);
  120.                   return (lp+1)&&(0xFFFF);
  121.                 }
  122.             break;
  123.         }
  124.     return VBDefControlProc(hctl, hwnd, msg, wp, lp);
  125. }
  126. // This routine handles the 'About' Dialog Box messages 
  127. BOOL FAR PASCAL _export AboutDlgProc
  128. (
  129.     HWND   hDlg,
  130.     USHORT msg,
  131.     USHORT wp,
  132.     LONG   lp
  133. )
  134. {
  135.     switch (msg)
  136.         {
  137.           case WM_CREATE:
  138.                 // Avoid warnings on unused (but required) formal parameters
  139.                 lp = lp;
  140.             return TRUE;
  141.         case WM_INITDIALOG:
  142.             return FALSE;
  143.         case WM_COMMAND:
  144.             if ((wp==IDOK)||(wp==IDCANCEL))
  145.                     EndDialog(hDlg, TRUE);
  146.                     return TRUE;
  147.         }
  148.     return FALSE;
  149. }
  150. //---------------------------------------------------------------------------
  151. // Register custom control. This routine is called by VB when the custom
  152. // control DLL is loaded for use.
  153. //---------------------------------------------------------------------------
  154. BOOL FAR PASCAL _export VBINITCC
  155. (
  156.     USHORT usVersion,
  157.     BOOL   fRuntime
  158. )
  159. {
  160.     // Avoid warnings on unused (but required) formal parameters
  161.     fRuntime  = fRuntime;
  162.     usVersion = usVersion;
  163.     // Register control(s)
  164.     return VBRegisterModel(hmodDLL, &modelBmpFilm);
  165. }
  166.  
  167.  
  168. //---------------------------------------------------------------------------
  169. // Initialize library.  This routine is called when the first client loads
  170. // the DLL.
  171. //---------------------------------------------------------------------------
  172. int FAR PASCAL LibMain
  173. (
  174.     HANDLE hModule,
  175.     WORD   wDataSeg,
  176.     WORD   cbHeapSize,
  177.     LPSTR  lpszCmdLine
  178. )
  179. {
  180.     // Avoid warnings on unused (but required) formal parameters
  181.     wDataSeg    = wDataSeg;
  182.     cbHeapSize  = cbHeapSize;
  183.     lpszCmdLine = lpszCmdLine;
  184.  
  185.     hmodDLL = hModule;
  186.  
  187.     return 1;
  188. }
  189. //---------------------------------------------------------------------------
  190. // WEP
  191. //---------------------------------------------------------------------------
  192. // C7 and QCWIN provide default a WEP:
  193. //---------------------------------------------------------------------------
  194. #if (_MSC_VER < 610)
  195. int FAR PASCAL WEP(int fSystemExit);
  196. //---------------------------------------------------------------------------
  197. // For Windows 3.0 it is recommended that the WEP function reside in a
  198. // FIXED code segment and be exported as RESIDENTNAME.  This is
  199. // accomplished using the alloc_text pragma below and the related EXPORTS
  200. // and SEGMENTS directives in the .DEF file.
  201. //
  202. // Read the comments section documenting the WEP function in the Windows
  203. // 3.1 SDK "Programmers Reference, Volume 2: Functions" before placing
  204. // any additional code in the WEP routine for a Windows 3.0 DLL.
  205. //---------------------------------------------------------------------------
  206. #pragma alloc_text(WEP_TEXT,WEP)
  207. //---------------------------------------------------------------------------
  208. // Performs cleanup tasks when the DLL is unloaded.  WEP() is
  209. // called automatically by Windows when the DLL is unloaded (no
  210. // remaining tasks still have the DLL loaded).    It is strongly
  211. // recommended that a DLL have a WEP() function, even if it does
  212. // nothing but returns success (1), as in this example.
  213. //---------------------------------------------------------------------------
  214. int FAR PASCAL WEP
  215. (
  216.     int fSystemExit
  217. )
  218. {
  219.     // Avoid warnings on unused (but required) formal parameters
  220.     fSystemExit = fSystemExit;
  221.     return 1;
  222. }
  223. #endif // C6
  224. //---------------------------------------------------------------------------
  225.